package com.yxt.ui;

import com.yxt.common.sys.CommConstant;
import com.yxt.common.sys.StringUtil;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 测站查询
 * @author TYP
 *
 */
public class StationSearchActivity extends Activity {
	private RadioButton radioSearchName;
	private RadioButton radioSearchRiver;
	private RadioButton radioSearchAddr;
	private RadioButton radioSearchAll;
	private Button btnSearch;
	private EditText txtValue;	
	private String searchType;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.station_search); // 软件activity的布局
		initComponent();
	}

	private void initComponent() {
		Button btnBackHome = (Button) findViewById(R.id.btnBackHome);		
		btnBackHome.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
			}
		});
		
		txtValue = (EditText) findViewById(R.id.txtValue);
		radioSearchName = (RadioButton)findViewById(R.id.radioSearchName);
		radioSearchRiver = (RadioButton)findViewById(R.id.radioSearchRiver);
		radioSearchAddr = (RadioButton)findViewById(R.id.radioSearchAddr);
		radioSearchAll = (RadioButton)findViewById(R.id.radioSearchAll);
		btnSearch = (Button)findViewById(R.id.btnSearch);
		
		btnSearch.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				String value = txtValue.getText().toString();
				if (StringUtil.isEmpty(value)) {
					Toast.makeText(getApplicationContext(), "查询条件不能为空", Toast.LENGTH_SHORT).show();
					return;
				}
				if (radioSearchName.isChecked()) {
					searchType = CommConstant.STATION_MAP.get(radioSearchName.getText().toString());
		    	} else if (radioSearchRiver.isChecked()) {
		    		searchType = CommConstant.STATION_MAP.get(radioSearchRiver.getText().toString());
		    	} else if (radioSearchAddr.isChecked()) {
		    		searchType = CommConstant.STATION_MAP.get(radioSearchAddr.getText().toString());
		    	} else if (radioSearchAll.isChecked()) {
		    		searchType = CommConstant.STATION_MAP.get(radioSearchAll.getText().toString());
		    	}
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), StationSearchResultActivity.class);
				intent.putExtra("value", value);
				intent.putExtra("type", searchType);
				startActivity(intent);
			}
			
		});
	}
	
	protected void onDestroy() {
		super.onDestroy();
	}
}